<template>
	<view>
		<navigation-bar :back="true" title="隐私协议"></navigation-bar>

		<view class="loading" v-if="loading">
			<text>正在加载隐私协议内容...</text>
		</view>

		<!-- <rich-text style="padding: 30rpx" :nodes="yinsi" v-else></rich-text> -->
		<view class="privacy-content" v-else v-html="this.yinsi"></view>
		
		<view class="error-message" v-if="error">
			<text>加载失败，请稍后重试</text>
		</view>
	</view>
</template>

<script>
	// pages/yinsi/yinsi.js
	export default {
		data() {
			return {
				yinsi: '',
				loading: true,
				error: false
			};
		},
		onLoad() {
			this.fetchPrivacyPolicy();
		},
		
		methods: {
			stripHtmlTags(html) {
			    // 移除所有HTML标签
			    return html.replace(/<[^>]*>/g, '');
			},
			fetchPrivacyPolicy() {
			    uni.request({
			        url: 'https://sdk.ssu8.cn/qqw.html',
			        method: 'GET',
			        success: (res) => {
			            console.log('请求成功:', res.statusCode, res.data.substring(0, 100));
			            // const data=this.stripHtmlTags(res.data);
						// console.log(res.data);
			            // 直接使用响应数据，不再判断success字段
			            if (res.statusCode === 200 && res.data) {
			                this.yinsi = res.data;
			                uni.setStorageSync('yinsi', this.yinsi);
			            } else {
			                console.error('响应异常:', res);
			                this.loadFromStorage();
			            }
			        },
			        fail: (err) => {
			            console.error('请求失败:', err);
			            this.loadFromStorage();
			        },
			        complete: () => {
			            this.loading = false;
			        }
			    });
			},
			loadFromStorage() {
				const cachedContent = uni.getStorageSync('yinsi');
				if (cachedContent) {
					this.yinsi = cachedContent;
				} else {
					this.error = true;
					this.yinsi = '<div>隐私协议内容加载失败</div>';
				}
			}
		}
	};
</script>
<style>
	/* pages/yinsi/yinsi.wxss */
</style>